/* Original name: Starting GDIplus
* Modified for minimum executable size by Henrik Haftmann
* Ownerdraw buttons are used inside the resource for 2 canvases
* Made for MSVC6, newer versions of Visual Studio need modifications
*/
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <objbase.h> // needed for DEFINE_GUID inside gdiplus.h
#include <gdiplus.h>
// Don't forget to remove /GZ compiler option for NODEFAULTLIB!
#pragma comment(linker,"/NODEFAULTLIB /OPT:nowin98") // no msvcrt.lib, reduce alignment space
#pragma comment(linker,"/LARGEADDRESSAWARE /RELEASE") // allow 3 GB address space, generate checksum
#define T(x) TEXT(x) // shorter macro - may conflict with template definitions
#define elemof(x) (sizeof(x)/sizeof(*(x))) // number of array elements
HINSTANCE HInstance; // global instance handle, needed for LoadIcon
extern "C" void _cdecl _fltused() {} // needed by MSVC6 when float is used (by gdiplus.h)
static BOOL CALLBACK AboutDlg(HWND Wnd, UINT msg, WPARAM wParam, LPARAM lParam) {
switch (msg) {
case WM_INITDIALOG: {
}return TRUE;
case WM_COMMAND: switch (wParam) {
case IDCANCEL:
case IDOK: EndDialog(Wnd,wParam); break;
}break;
}
return FALSE;
}
static BOOL CALLBACK StartingGDIPlusDlg(HWND Wnd, UINT msg, WPARAM wParam, LPARAM lParam) {
switch (msg) {
case WM_INITDIALOG: { // when dialog is populated with all child windows
SetClassLong(Wnd,GCL_HICON,(LONG)LoadIcon(HInstance,MAKEINTRESOURCE(1)));
HMENU SysMenu=GetSystemMenu(Wnd,FALSE);
TCHAR strAboutMenu[64];
LoadString(0,16,strAboutMenu,elemof(strAboutMenu));
AppendMenu(SysMenu,MF_SEPARATOR,-1,0);
AppendMenu(SysMenu,MF_STRING,16,strAboutMenu); // Append about dialog option to system menu
}return TRUE; // let dialog manager set focus to first focusable element (here: OK button)
case WM_SYSCOMMAND: switch (wParam&~15) { // when system menu item is chosen
case 16: DialogBox(HInstance,MAKEINTRESOURCE(16),Wnd,AboutDlg); break;
}break; // Normally, HInstance can be replaced by 0 for Win32 programs,
// but then the Icon resource is not found by DialogBox(). Undocumented.
case WM_DRAWITEM: { // when ownerdraw elements need to repaint
DRAWITEMSTRUCT*dis=(DRAWITEMSTRUCT*)lParam; // Let compiler remove unnecessary assignments
using namespace Gdiplus;
Graphics g(dis->hDC);
switch (dis->CtlID) { // Which child?
case 10: { // large left child window (ownerdraw button)
Pen blue (Color(255, 0, 0, 255));
Pen red (Color(255, 255, 0, 0));
int y = dis->rcItem.bottom;
for (int x=dis->rcItem.left; x<dis->rcItem.right; x+=5) {
g.DrawLine(&blue, dis->rcItem.left, y, x, dis->rcItem.top);
g.DrawLine(&red, dis->rcItem.right, x, y, dis->rcItem.bottom);
y-=5;
}
for (y=0; y<256; y++) {
Pen pen(Color(y, 0, 255,0)); // A green pen with varying alpha, width = 1 pixel
g.DrawLine(&pen,0,y,256,y); // More performance would bring a GradientFill
} // The green pen gets deleted here by C++ compiler
for (x=0; x<256; x++) {
Pen pen(Color(x, 255, 0, 255)); // A magenta pen with varying alpha
g.DrawLine(&pen,x,100,x,200);
} // Auto-deletion of magenta pen here
}break; // Auto-deletion of blue and red pen here
case 11: { // small top-right child window
Image img(L"ma2bw1.jpg");
Rect r(dis->rcItem.left,dis->rcItem.top,
dis->rcItem.right-dis->rcItem.left,dis->rcItem.bottom-dis->rcItem.top);
g.DrawImage(&img,r);
}break; // Auto-deletion of loaded image here
}
}break; // Auto-deletion of Graphics g
case WM_COMMAND: switch (wParam) {
case IDCANCEL:
case IDOK: EndDialog(Wnd,wParam); break; // Both cases use same EndDialog()
}
}
return FALSE;
}
int WINAPI WinMainCRTStartup(){ // no WinMain entry due to NODEFAULTLIB
ULONG_PTR gdiplusToken;
HInstance=GetModuleHandle(0);
Gdiplus::GdiplusStartupInput gdiplusStartupInput;
Gdiplus::GdiplusStartup(&gdiplusToken,&gdiplusStartupInput,0);
DialogBox(HInstance,MAKEINTRESOURCE(1),0,StartingGDIPlusDlg);
Gdiplus::GdiplusShutdown(gdiplusToken);
ExitProcess(0);
}
Vorgefundene Kodierung: ASCII (7 bit) | 2
|